# encoding: utf-8
# author: 侯佳涛
# file_name: 1.jsonpath_test
# create_time: 2021/5/21, 下午6:20
"""
jsonpath语法：
    $: 根结点
    .: 子节点
    ..: 子孙节点
"""

import jsonpath

# # jsonpath测试一
# data_dict = {'key1': {'key2': {'key3': {'key4': {'key5': 'python'}}}}}
# # jsonpath提取的数据是列表
# print(jsonpath.jsonpath(data_dict, '$..key5'))

# jsonpath测试二
book_dict = {
    "store": {
        "book": [
            {"category": "reference",
             "author": "Nigel Rees",
             "title": "Sayings of the Century",
             "price": 8.95
             },
            {"category": "fiction",
             "author": "Evelyn Waugh",
             "title": "Sword of Honour",
             "price": 12.99
             },
            {"category": "fiction",
             "author": "Herman Melville",
             "title": "Moby Dick",
             "isbn": "0-553-21311-3",
             "price": 8.99
             },
            {"category": "fiction",
             "author": "J. R. R. Tolkien",
             "title": "The Lord of the Rings",
             "isbn": "0-395-19395-8",
             "price": 22.99
             }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    }
}

# store中的所有的book作者
print(jsonpath.jsonpath(book_dict, '$..author'))
print(jsonpath.jsonpath(book_dict, '$.[*].author'))

# # 查询所有节点
# print(jsonpath.jsonpath(book_dict, '$..'))
# print(jsonpath.jsonpath(book_dict, '$.[]'))


